package ming.model.type;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.StringUtils;

@SuppressWarnings("serial")
@Entity
@Table(name = "T_TOBACCO_PUBLISH", schema = "")
public class Publish implements java.io.Serializable {

	// Fields

	private String id;
	private String title;
	private String content;
	private Integer publish;//0为未发布，1为已发布
	private Publishtype publishtype;
	private String orgcode;
	private Date publishTime;
	private Date createtime;
	private String createuser;
	private Set<Terminal> terminals = new HashSet<Terminal>(0);

	// Property accessors
	@Id
	@Column(name = "vcId", unique = true, nullable = false, length = 36)
	public String getId() {
		if (!StringUtils.isBlank(this.id)) {
			return this.id;
		}
		return UUID.randomUUID().toString();
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "vcTitle", nullable = false, length = 200)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "vcContent", length = 65535)
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name = "intPublish")
	public Integer getPublish() {
		return this.publish;
	}

	public void setPublish(Integer publish) {
		this.publish = publish;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "vcType")
	public Publishtype getPublishtype() {
		return this.publishtype;
	}

	public void setPublishtype(Publishtype publishtype) {
		this.publishtype = publishtype;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dtPublishTime", length = 19)
	public Date getPublishTime() {
		return this.publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_tobacco_publish_terminal", schema = "", joinColumns = { @JoinColumn(name = "vcPublish_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "vcTerminal_ID", nullable = false, updatable = false) })
	public Set<Terminal> getTerminals() {
		return this.terminals;
	}

	public void setTerminals(Set<Terminal> terminals) {
		this.terminals = terminals;
	}

	@Column(name = "orgcode")
	public String getOrgcode() {
		return orgcode;
	}

	public void setOrgcode(String orgcode) {
		this.orgcode = orgcode;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "createtime")
	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	@Column(name = "createuser")
	public String getCreateuser() {
		return createuser;
	}

	public void setCreateuser(String createuser) {
		this.createuser = createuser;
	}
}